//
//  UIAlertView+Helpers.m
//  Rockval
//
//  Created by TuanNT on 4/27/14.
//  Copyright (c) 2014 TNL. All rights reserved.
//

#import "UIAlertView+Helpers.h"
#import "SHAlertViewBlocks.h"

#define MESSAGE_TITLE_ERROR @"Error"
#define MESSAGE_TITLE_WARNING @"Warning"

#define MESSAGET_BUTTON_OK @"OK"
#define MESSAGET_BUTTON_CANCEL @"Cancel"
#define MESSAGET_BUTTON_DISMISS @"Dismiss"

@implementation UIAlertView (Helpers)

+ (void)showErrorAlertViewWithMessage:(NSString *)message {
	[UIAlertView showErrorAlertViewWithMessage:message dismissBlock:nil];
}

+ (void)showErrorAlertViewWithMessage:(NSString *)message dismissBlock:(void (^)())dismissBlock {
	[UIAlertView showAlertViewWithTitle:MESSAGE_TITLE_ERROR message:message dismissBlock:dismissBlock];
}

+ (void)showWarningAlertViewWithMessage:(NSString *)message {
	[UIAlertView showWarningAlertViewWithMessage:message dismissBlock:nil];
}

+ (void)showWarningAlertViewWithMessage:(NSString *)message dismissBlock:(void (^)())dismissBlock {
	[UIAlertView showAlertViewWithTitle:MESSAGE_TITLE_WARNING message:message dismissBlock:dismissBlock];
}

+ (void)showAlertViewWithMessage:(NSString *)message {
	[UIAlertView showAlertViewWithTitle:nil message:message];
}

+ (void)showAlertViewWithMessage:(NSString *)message dismissBlock:(void (^)())dismissBlock {
	[UIAlertView showAlertViewWithTitle:nil message:message dismissBlock:dismissBlock];
}

+ (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message {
	[UIAlertView showAlertViewWithTitle:title message:message dismissBlock:nil];
}

+ (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message dismissBlock:(void (^)())dismissBlock {
	[[UIAlertView SH_alertViewWithTitle:title
	                         andMessage:message
	                       buttonTitles:nil
	                        cancelTitle:MESSAGET_BUTTON_DISMISS
	                          withBlock: ^(NSInteger theButtonIndex) {
	    if (dismissBlock) {
	        dispatch_async(dispatch_get_main_queue(), ^{
	            dismissBlock();
			});
		}
	}] show];
}

+ (void)showErrorConfirmAlertViewWithMessage:(NSString *)message okBlock:(void (^)())okBlock {
	[UIAlertView showErrorConfirmAlertViewWithMessage:message okBlock:okBlock cancelBlock:nil];
}

+ (void)showErrorConfirmAlertViewWithMessage:(NSString *)message okBlock:(void (^)())okBlock cancelBlock:(void (^)())cancelBlock {
	[UIAlertView showConfirmAlertViewWithTitle:MESSAGE_TITLE_ERROR message:message okBlock:okBlock cancelBlock:cancelBlock];
}

+ (void)showConfirmAlertViewWithTitle:(NSString *)title message:(NSString *)message okBlock:(void (^)())okBlock cancelBlock:(void (^)())cancelBlock {
	[[UIAlertView SH_alertViewWithTitle:title
	                         andMessage:message
	                       buttonTitles:@[MESSAGET_BUTTON_OK]
	                        cancelTitle:MESSAGET_BUTTON_CANCEL
	                          withBlock: ^(NSInteger theButtonIndex) {
	    if (theButtonIndex == 0) {
	        if (cancelBlock) {
	            dispatch_async(dispatch_get_main_queue(), ^{
	                cancelBlock();
				});
			}
	        return;
		}
	    if (okBlock) {
	        dispatch_async(dispatch_get_main_queue(), ^{
	            okBlock();
			});
		}
	}] show];
}

@end
